package com.wyl.selenium.common;

import cn.hutool.core.lang.UUID;
import com.wyl.selenium.enums.ResponseCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @Description
 * @Author WuYiLong
 * @Date 2023/11/13 11:18
 */
@Data
@ApiModel(value = "响应体")
public class ResponseData<T>  {
    @ApiModelProperty(value = "响应消息")
    private String msg;
    @ApiModelProperty(value = "响应码")
    private Integer code;
    @ApiModelProperty(value = "响应体")
    private T data;
    @ApiModelProperty(value = "请求id")
    private String requestId = UUID.fastUUID().toString().replace("-","");
    @ApiModelProperty(value = "保留数据")
    private String reserveData;


    public ResponseData() {};
    public ResponseData(Integer code,String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseData(Integer code,String msg,T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResponseData(Integer code,String msg,T data,String requestId) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.requestId = requestId;
    }

    public ResponseData(Integer code,String msg,T data,String requestId,String reserveData) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.requestId = requestId;
        this.reserveData = reserveData;
    }

    public static <T> ResponseData<T> success() {
        return new ResponseData<T>(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getMessage());
    }

    public static <T> ResponseData<T> successInstance(T data) {
        return new ResponseData<T>(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getMessage(),data);
    }

    public static <T> ResponseData<T> fail() {
        return new ResponseData<T>(ResponseCode.FAIL.getCode(),ResponseCode.FAIL.getMessage());
    }
}
